<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of mmw_mapper_Mapper
 *
 * @author Manu
 */
require_once(dirname(__FILE__) . '/../core/mmw_core_ApplicationRegistry.php');
require_once(dirname(__FILE__) . '/../core/mmw_core_AppException.php');
    
abstract class mmw_mapper_Mapper {

    protected static $PDO;

    public function __construct() {
        if (!isset(self::$PDO)) {
            $dsn = mmw_core_ApplicationRegistry::getKey("dsn");
            $user = mmw_core_ApplicationRegistry::getKey("user");
            $password = mmw_core_ApplicationRegistry::getKey("password");


            try {
                self::$PDO = new PDO($dsn, $user, $password);
            } catch (PDOException $e) {
                throw new mmw_core_AppException("Connection to db failed: " . $e->getMessage());
            }
        }
    }

    protected function createObjectArray($array) {
        $objArray=array();
        
        for ($i = 0; $i < count($array); $i++) {
            $objArray[$i] = $this->createObject($array[$i]);
        }
        
        return $objArray;
    }
    
    protected abstract function createObject($array);

}

?>
